package asapIs134CK.womi.client.games.logoGame.froggitTheFrog.editor;

import asapIs134CK.womi.client.games.logoGame.froggitTheFrog.Cell;

import com.allen_sauer.gwt.dnd.client.HasDragHandle;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class CellGUI extends AbsolutePanel implements HasDragHandle{

	private FocusPanel shim = new FocusPanel();

	private Cell _cell;
	private Image _gui;

	public CellGUI(Cell c){
		_cell = c;
		_gui = _cell.getImage();
		this.add(_gui);

	}

	public CellGUI clone(){
		return new CellGUI(_cell.clone());
	}

	public void addClickHandler(ClickHandler clickHandler) {
		//shim.addClickHandler(clickHandler);
		//_gui.addClickHandler(clickHandler);
	}

	public Image getGUI(){
		return _gui;
	}
	public Cell getCell(){
		return _cell;
	}
	@Override
	public Widget getDragHandle() {
		// TODO Auto-generated method stub
		return shim;
	}

	/**
	 * Adjust the shim size and attach once our widget dimensions are known.
	 */
	@Override
	protected void onLoad() {
		super.onLoad();
		shim.setPixelSize(getOffsetWidth(), getOffsetHeight());
		add(shim, 0, 0);
	}

	/**
	 * Remove the shim to allow the widget to size itself when reattached.
	 */
	@Override
	protected void onUnload() {
		super.onUnload();
		shim.removeFromParent();
	}
	/**
	 * Let shim size match our size.
	 * 
	 * @param width the desired pixel width
	 * @param height the desired pixel height
	 */
	@Override
	public void setPixelSize(int width, int height) {
		super.setPixelSize(width, height);
		shim.setPixelSize(width, height);
	}

	/**
	 * Let shim size match our size.
	 * 
	 * @param width the desired CSS width
	 * @param height the desired CSS height
	 */
	@Override
	public void setSize(String width, String height) {
		super.setSize(width, height);
		shim.setSize(width, height);
	}
}